const Mock = require('mockjs');

const memberDiscountData = Mock.mock({
  'list|10': [{
    'strategyId|+1': 1,
    'type|1': ['open', 'renew'],
    'discount|1': [0.5, 0.6, 0.7, 0.8, 0.9],
    'startTime': '@datetime',
    'endTime': '@datetime',
    'userCondition|1': ['register_1day', 'visited_vip'],
    'isEnabled|1': [true, false]
  }]
});

const statsData = {
  total: 10,
  enabled: 7,
  disabled: 3,
  active: 5
};

module.exports = [
  // 获取折扣策略列表
  {
    url: '/backend/memberDiscount/getList',
    type: 'get',
    response: config => {
      const { pageIndex = 1, pageSize = 20 } = config.query;
      const list = memberDiscountData.list.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
      
      return {
        code: 200,
        message: 'success',
        data: {
          list,
          total: memberDiscountData.list.length,
          pageIndex: parseInt(pageIndex),
          pageSize: parseInt(pageSize)
        }
      };
    }
  },

  // 获取折扣策略详情
  {
    url: '/backend/memberDiscount/getDetail',
    type: 'get',
    response: config => {
      const { id } = config.query;
      const item = memberDiscountData.list.find(item => item.strategyId == id);
      
      return {
        code: 200,
        message: 'success',
        data: item || {}
      };
    }
  },

  // 新增折扣策略
  {
    url: '/backend/memberDiscount/create',
    type: 'post',
    response: config => {
      return {
        code: 200,
        message: '创建成功',
        data: null
      };
    }
  },

  // 更新折扣策略
  {
    url: '/backend/memberDiscount/update',
    type: 'put',
    response: config => {
      return {
        code: 200,
        message: '更新成功',
        data: null
      };
    }
  },

  // 删除折扣策略
  {
    url: '/backend/memberDiscount/delete',
    type: 'delete',
    response: config => {
      return {
        code: 200,
        message: '删除成功',
        data: null
      };
    }
  },

  // 切换折扣策略状态
  {
    url: '/backend/memberDiscount/toggleStatus',
    type: 'put',
    response: config => {
      return {
        code: 200,
        message: '状态切换成功',
        data: null
      };
    }
  },

  // 批量删除折扣策略
  {
    url: '/backend/memberDiscount/batchDelete',
    type: 'delete',
    response: config => {
      return {
        code: 200,
        message: '批量删除成功',
        data: null
      };
    }
  },

  // 获取折扣策略统计信息
  {
    url: '/backend/memberDiscount/getStats',
    type: 'get',
    response: config => {
      return {
        code: 200,
        message: 'success',
        data: statsData
      };
    }
  }
];

